#pragma once

#include <vector>
#include <algorithm>
using std::vector;
using std::sort;
using std::find;

template <typename T>
class Comparison
{
	bool operator()(T a, T b)
	{
		return a > b;
	}
};

template <typename T, typename Comp = Comparison<T>>
class ordered_vector : public vector<T>
{
public: //interface
	bool erase(T _Val)
	{
		typedef vector<T>::iterator VI;

		VI vi = find(begin(), end(), _Val);
		if(vi != end())
		{
			vector<T>::erase(vi);
			return true;
		}
		return false;
	}

	void insert(T _Val)
	{
		if(empty())
		{
			vector<T>::push_back(_Val);
		}
		else
		{
			if(_Val < front())
			{
				vector<T>::insert(begin(), _Val);
				return;
			}
			if(_Val > back())
			{
				vector<T>::push_back(_Val);
				return;
			}
			for(int i = 1; i < int(size() - 1); i++)
			{
				if(_Val >= at(i-1) && _Val < at(i))
				{
					vector<T>::insert(begin() + i, _Val);
					return;
				}
			}
		}
	}
public:
	iterator insert(iterator _Where, const T& _Val);
	void insert(iterator _Where, size_type _Count, const T& _Val);
template<class InputIterator>
	void insert(iterator _Where, InputIterator _First, InputIterator _Last);
	void push_back(const T& _Val);
	void pop_back();
public:
	ordered_vector(void) {}
public:
	class UnsupportedException {};
};
